package com.app.toknow.Activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;

import com.app.toknow.R;

import com.app.toknow.View.ToastDialog;

public class RegisterOneActivity extends BaseActivity implements View.OnClickListener {
    private ToastDialog toastDialog;
    private TextView tvUserName;
    private TextView tvPassWord;
    private TextView tvRePassWord;
    private TextView tvEmail;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register_one);
        initContentView();
    }

    private void initContentView(){
        findViewById(R.id.register_one_rootLayout).setOnClickListener(this);
        tvUserName = (TextView)findViewById(R.id.edittext_account);
        tvPassWord = (TextView)findViewById(R.id.edittext_password);
        tvRePassWord = (TextView)findViewById(R.id.edittext_repassword);
        tvEmail = (TextView)findViewById(R.id.edittext_email);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        Log.e("main", "onkeydown");
        if(keyCode==KeyEvent.KEYCODE_BACK){
            finish();
        }
        return false;
    }
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_back:
                this.finish();
                break;
            case R.id.register_one_rootLayout:
                InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                break;
            case R.id.button_next:
                boolean flag = true;
                if(tvUserName.getText().toString().equals(""))
                {
                    toastDialog = ToastDialog.createToastConfig();
                    toastDialog.ToastShow(getApplicationContext(),"用户名为空");
                    flag = false;
                    return;
                }
                Intent intent = new Intent(RegisterOneActivity.this,RegisterTwoActivity.class);
                intent.putExtra("username", tvUserName.getText().toString());
                intent.putExtra("password", tvPassWord.getText().toString());
                intent.putExtra("repassword", tvRePassWord.getText().toString());
                intent.putExtra("email", tvEmail.getText().toString());
                startActivity(intent);
                break;
            default:
                break;
        }
    }
}
